package utils

import (
	"io"
	"lingc/config"

	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

const (
	endpoint        = config.Endpoint
	accessKeyID     = config.AccessKeyId
	accessKeySecret = config.AccessKeySecret
	bucketName      = config.Bucket
)

// 上传文件到 OSS
func UploadToOSS(file io.Reader, objectKey string) error {
	// 创建 OSS 客户端实例
	client, err := oss.New(endpoint, accessKeyID, accessKeySecret)
	if err != nil {
		return err
	}

	// 获取存储空间
	bucket, err := client.Bucket(bucketName)
	if err != nil {
		return err
	}

	// 上传文件到 OSS
	err = bucket.PutObject(objectKey, file)
	if err != nil {
		return err
	}

	return nil
}
